import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
const $time 	= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		receiveStatus : [{ name:'已领取', value:1 }],
		// 搜索表单列表
		forms : [
			{ label: '条码号',		name: 'spec_code' },
			{ label: '领取人',		name: 'receive_user' },
			{ label: '标本架',		name: 'sf_number' },
			{ label: '实验号',		name: 'experiment_num' },
			{ label: '岗位',		name: 'project_name',				type:'select', 		loading:true},
			{ label: '科室',		name: 'team_name',					type:'select',		loading:true,	idStr:'uuid',},
			{ label: '领取时间',		names: ['start_time','end_time'], 	type:'date-range', 	loading:true,	name:'jz-time', },
			{ label: '接收时间',		names: ['start_receive_time','end_receive_time'],	name:'jz-time_1', 	type:'date-range', 	loading:true },
		],
	}
	model = {}
	
	componentDidMount(){
		this.getSelect()
		$time.then(f=>{
			const arr = f.duration['1-9-9']()
			this.resetModel = { start_time: arr[0], end_time: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 科室
			$fn.setRow( forms, 'team_name', await f.getCache({ api:'ke_shi' }) )
			// 岗位
			$fn.setRow( forms, 'project_name', await f.getCache({ api:'gang_wei' }) )
			 
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'receive/logs' )
	
	// 表单
	cols = [
		{ title: '标本条码号', 	dataIndex: 'spec_code', 			...$fn.table.spec_code },
		{ title: '实验号', 		dataIndex: 'lb_tpl', 				...$fn.table.spec_code, 	sorter:true, },
		{ title: '标本架编号', 	dataIndex: 'sf_number', 			...$fn.table.spec_code },
		{ title: '创建人', 		dataIndex: 'founder', 				...$fn.table.name },
		{ title: '创建时间', 	dataIndex: 'created_at',  			...$fn.table.time},
		{ title: '领取人', 		dataIndex: 'receive_user', 			...$fn.table.name},
		{ title: '领取时间', 	dataIndex: 'receive_time',  		...$fn.table.time},
		{ title: '接收时间', 	dataIndex: 'sp_receive_time',  		...$fn.table.time},
		{ title: '岗位', 		dataIndex: 'job_id', 				width:150 },
		{ title: '科室', 		dataIndex: 'team_name', 			width:150 },
		{ title: '状态', 		dataIndex: 'handover_type', 		width:100,			render: text => $fn.getState(this.state.receiveStatus,text) },
	]
	
	render(){
		return (
			<Page title='标本领取记录'>
				{/* 搜索 */}
				{ SearchForm.call(this, {timeStr:'1-9-9'}) }
				{/* 表格 */}
				{ Table.call(this, {isInit: window.isInit}) }
			</Page>
		)
	}
}

export default Index